//测试Schlick的Fresnel的像素着色器

//顶点着色器输出
struct VS_OUTPUT
{
    float4 Pos : SV_POSITION;
    float3 Normal : NORMAL;
	float2 TexCoord : TEXCOORD0;
	float3 WorldPosition : TEXCOORD1;
};

TextureCube skyboxCubeMap : register( t9 );
SamplerState ourSampler : register( s5 );

cbuffer SceneData : register( b7 )
{
	matrix View;
	matrix Projection;
	float4 lightDir;
	float4 eyePosition;
}

float3 Fresnel_Schlick(float3 F0, float3 normal, float3 view)
{
	float cosTheta = dot(normalize(view), normalize(normal));
	return F0 + (float3(1, 1, 1) - F0) * pow(1 - cosTheta, 5);
}

float4 Main( VS_OUTPUT input ) : SV_Target
{
	//测试的F0：
	//float3 TestF0 = float3(0.25, 0.25, 0.25);
	float3 TestF0 = float3(1.0, 0.886, 0.608);
	
	//视线方向
	float3 ViewDir = eyePosition.xyz - input.WorldPosition;
	
	//菲涅尔值
	float3 Fresnel = Fresnel_Schlick(TestF0, input.Normal, ViewDir);

	//反射光的方向
	float3 ReflectDir = reflect(normalize(ViewDir), normalize(input.Normal));
	//反射的环境光颜色从天空盒采样
	float4 ReflectColor = skyboxCubeMap.Sample(ourSampler, -ReflectDir);
	
	//输出菲涅尔值乘算反射的环境光颜色
	return float4(Fresnel, 1.0) * ReflectColor;
}
